$.fn.extend({
  SplitID: function() {
    return this.attr('id').split('-').pop();
  },

  Slideshow: {
    Ready: function() {
      $('.slideshow-control')
      .hover(
        function() {
          $(this).addClass('slideshow-control-on');
        },
        function() {
          $(this).removeClass('slideshow-control-on');
        }
        )

      .click(
        function() {
          $.fn.Slideshow.Interrupted = true;

          $('.slide').hide();
          $('.slideshow-control').removeClass('active');

          $('#slide-' + $(this).SplitID()).show();
          $(this).addClass('active');
        }
        );

      this.Counter = 1;
      this.Interrupted = false;

      this.Transition();
    },

    Transition: function() {
      if (this.Interrupted) {
        return;
      }

      this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = 3;
      }

      $('#slide-' + this.Last).fadeOut('fast', function() {
        $('#slideshow-control-' + $.fn.Slideshow.Last).removeClass('active');
        $('#slideshow-control-' + $.fn.Slideshow.Counter).addClass('active');
        $('#slide-' + $.fn.Slideshow.Counter).fadeIn('fast');

        $.fn.Slideshow.Counter++;

        if ($.fn.Slideshow.Counter > 3) {
          $.fn.Slideshow.Counter = 1;
        }

        setTimeout('$.fn.Slideshow.Transition();', 5000);
      });
    }
  }
});